package com.bys.util;

import com.obs.services.ObsClient;

import java.io.IOException;
import java.io.InputStream;

public class ObsUtils {


    public static String uploadFile(InputStream ins, String fileName){
        if(FileUtils.isVideoFile(fileName)){
            fileName = "video/"+fileName;
        }else if(FileUtils.isImage(fileName)){
            fileName = "images/"+fileName;
        }
        String endPoint = "obs.cn-east-3.myhuaweicloud.com";
        String ak = "PS1J081FZCA6EEZYTDG1";
        String sk = "skuWqKgKTSyIT9QXjurA6TnLLUAXKF2qsmcVLYre";
        ObsClient obsClient = new ObsClient(ak, sk, endPoint);
        String bucketName = "ice-content";
        obsClient.putObject(bucketName, fileName, ins);
        try {
            obsClient.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return "https://"+bucketName+"."+endPoint+"/" + fileName;
    }
}

